package com.koron.css2.clientCenter.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.NoticeBean;
import com.koron.css2.clientCenter.mapper.NoticeMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.ValidationKey;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Map;

/**
 * 通知公告添加
 * 
 * @author 杨嘉慧
 *
 */
public class NoticeAdd implements ServerInterface {

	@Override
	@ValidationKey(clazz = NoticeBean.class, method = "insert")
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			NoticeBean notice = JsonUtils.objectToPojo(req.getData(), NoticeBean.class);
			NoticeMapper noticeMapper = factory.getMapper(NoticeMapper.class);
			notice.setCreateInfo(userInfo);
			noticeMapper.noticeAdd(notice);
			return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "通知公告添加成功", Map.class);
		} catch (Exception e) {
			logger.error("通知公告添加失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "执行失败", null);
		}
	}
}
